package com.zd.service.impl;

import com.github.pagehelper.PageHelper;
import com.zd.mapper.UserInfoMapper;
import com.zd.model.UserInfo;
import com.zd.service.IUserInfoService;
import com.zd.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;


    @Override
    public List<UserInfo> selectByPrimaryKey(int pageNum, int pageSize, UserInfo queryUserInfo) {

        PageHelper.startPage(pageNum, pageSize);

        List<UserInfo> userInfoList = userInfoMapper.selectByPrimaryKey(queryUserInfo);

        return userInfoList;
    }

    @Override
    public boolean insertUserInfo(UserInfo userInfo) {

        //MD5加密
        userInfo.setPassword(MD5Util.encode(userInfo.getPassword()));


        return userInfoMapper.insertSelective(userInfo)>0?true:false;
    }

    @Override
    public boolean resetPassword(UserInfo userInfo) {
        //MD5加密
        userInfo.setPassword(MD5Util.encode(userInfo.getPassword()));

        return userInfoMapper.updateByPrimaryKeySelective(userInfo)>0?true:false;
    }

    @Override
    public boolean deleteUserInfo(int id) {

        UserInfo userInfo=new UserInfo();

        userInfo.setId(new Long(id));

        userInfo.setFlag(0);

        return userInfoMapper.updateByPrimaryKeySelective(userInfo)>0?true:false;
    }
}
